<?php

namespace App\Modules\Admin\Controllers;


use App\Models\Site;
use Illuminate\Http\Request;

class SiteController extends Controller
{
    public function index()
    {
        return view('admin::site', ['site' => Site::first()]);
    }

    public function save(Request $request)
    {
        $params = $request->all();
        if (isset($params['id'])) {
            Site::query()->where('id', $params['id'])->update([
                'name'          => $params['name'],
                'contact_email' => $params['contact_email'],
                'keywords'      => $params['keywords'],
                'description'   => $params['description'],
            ]);
        } else {
            Site::create([
                'name'          => $params['name'],
                'contact_email' => $params['contact_email'],
                'keywords'      => $params['keywords'],
                'description'   => $params['description'],
            ]);
        }
        return redirect()->route('admin.site');
    }
}
